package com.ewanghuiju.app.presenter.main;


import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.main.RedEnvelopesContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.RedEnvelopesDetailsResponBean;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/16
 */
public class RedEnvelopesPresenter extends RxPresenter<RedEnvelopesContract.View> implements RedEnvelopesContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public RedEnvelopesPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getData(int page) {
        addSubscribe(mDataManager.ptiLuckydrawList()
                        .compose(RxUtil.rxSchedulerHelper())
                        .compose(RxUtil.handleMyResultCannull())
                        .subscribeWith(new CommonSubscriber<Optional<RedEnvelopesDetailsResponBean>>(mView) {
                            @Override
                            public void onNext(Optional<RedEnvelopesDetailsResponBean> optional) {
                                if (mView != null)
                                    mView.showContent(optional.getIncludeNull());
                            }

                            @Override
                            public void onError(Throwable e) {
                                super.onError(e);
//                        if (mView != null)
//                            mView.showContentError();
                            }
                        })
        );
    }
}
